package com.googlecode.groovy_toy_orm

import groovy.sql.Sql

/**
 * @author: DavydovMD
 * Date: 05.04.13
 * Time: 13:07
 */
class DbProcedureMapper extends Mapper {
    Closure<Sql> dbGetter
    String spName

    DbProcedureMapper(MapperFields builder, Closure<Sql> dbGetter, String storedProcedureName) {
        super(builder)
        this.spName = storedProcedureName
        this.dbGetter = dbGetter
    }

    DbProcedureMapper(Mapper mapper, Closure<Sql> dbGetter, String storedProcedureName) {
        super(mapper)
        this.spName = storedProcedureName
        this.dbGetter = dbGetter
    }

    def <T> Map execStoredProc(T bean) {
        SqlMappingUtil.executeSp(dbGetter(), spName, bean, this)
    }

    def <T> Map execStoredProcWithParams(Map params) {
        SqlMappingUtil.executeSpWithParams(dbGetter(), spName, params, this)
    }
}
